from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


class MeiduoPagination(PageNumberPagination):
    # 默认页大小
    page_size = 10
    # 最大页大小
    max_page_size = 100
    # 查询参数中页大小的键
    page_size_query_param = 'pagesize'

    # 重写分页的响应体方法
    def get_paginated_response(self, data):
        return Response({
            # 数据的总数量
            "counts": self.page.paginator.count,
            # 当前页内容
            "lists": data,
            # 当前页码
            "page": self.page.number,
            # 总页码
            "pages": self.page.paginator.num_pages,
            # 每页数据数量
            "pagesize": self.page_size,
        })
